package com.zwps.biz.domain.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zwps.biz.dal.db.dao.WeatherRadarDAO;
import com.zwps.biz.dal.db.object.WeatherRadarDO;
import com.zwps.biz.domain.service.WeatherRadarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 *
 */
@DS("lhk")
@Service
public class WeatherRadarServiceImpl extends ServiceImpl<WeatherRadarDAO, WeatherRadarDO>
    implements WeatherRadarService{
    @Autowired
    WeatherRadarDAO weatherRadarDAO;

    @Override
    public List<WeatherRadarDO> getWeatherRadar(String startTime, String endTime,Integer type) {
        if (type==null){
            type=1;
        }
        LambdaQueryWrapper<WeatherRadarDO> queryWrapper = new LambdaQueryWrapper<>();
        if (startTime!=null && endTime!=null){
            queryWrapper.between(WeatherRadarDO::getTime,startTime,endTime);
        }else {
            queryWrapper.last("limit 15");
        }
        queryWrapper.eq(WeatherRadarDO::getType,type);
        queryWrapper.groupBy(WeatherRadarDO::getTime, WeatherRadarDO::getYear, WeatherRadarDO::getImage).orderByDesc(WeatherRadarDO::getTime);
        List<WeatherRadarDO> list = this.list(queryWrapper);

        return list;
    }

    @Override
    public Set<LocalDateTime> getExistingTimes(Integer type) {
        return weatherRadarDAO.getExistingTimes( type);
    }
}




